import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class GeometryCalculatorGUI {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            createAndShowGUI();
        });
    }

    private static void createAndShowGUI() {
        JFrame frame = new JFrame("几何图形计算器");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 600);
        frame.setLayout(new BorderLayout());

        // 主面板
        JPanel mainPanel = new JPanel(new BorderLayout());

        // 标题
        JLabel titleLabel = new JLabel("几何图形计算器", JLabel.CENTER);
        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
        titleLabel.setForeground(Color.BLUE);

        // 按钮面板
        JPanel buttonPanel = new JPanel(new GridLayout(2, 3, 10, 10));
        buttonPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

        // 创建按钮
        JButton circleBtn = createStyledButton("圆形");
        JButton triangleBtn = createStyledButton("三角形");
        JButton rectangleBtn = createStyledButton("矩形");
        JButton trapezoidBtn = createStyledButton("梯形");
        JButton parallelogramBtn = createStyledButton("平行四边形");
        JButton exitBtn = createStyledButton("退出");
        exitBtn.setBackground(Color.RED);
        exitBtn.setForeground(Color.WHITE);

        // 添加按钮监听器
        circleBtn.addActionListener(e -> CircleGUI.showCircleWindow());
        triangleBtn.addActionListener(e -> TriangleGUI.showTriangleWindow());
        rectangleBtn.addActionListener(e -> RectangleGUI.showRectangleWindow());
        trapezoidBtn.addActionListener(e -> TrapezoidGUI.showTrapezoidWindow());
        parallelogramBtn.addActionListener(e -> ParallelogramGUI.showParallelogramWindow());
        exitBtn.addActionListener(e -> System.exit(0));

        // 添加按钮到面板
        buttonPanel.add(circleBtn);
        buttonPanel.add(triangleBtn);
        buttonPanel.add(rectangleBtn);
        buttonPanel.add(trapezoidBtn);
        buttonPanel.add(parallelogramBtn);
        buttonPanel.add(exitBtn);

        // 添加组件到主面板
        mainPanel.add(titleLabel, BorderLayout.NORTH);
        mainPanel.add(buttonPanel, BorderLayout.CENTER);

        frame.add(mainPanel);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    private static JButton createStyledButton(String text) {
        JButton button = new JButton(text);
        button.setFont(new Font("微软雅黑", Font.BOLD, 16));
        button.setBackground(new Color(70, 130, 180));
        button.setForeground(Color.WHITE);
        button.setFocusPainted(false);
        button.setBorder(BorderFactory.createRaisedBevelBorder());
        return button;
    }
}